package com.ruoyi.web.controller.goods;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goods.GoodsStore.domain.Goods;
import com.ruoyi.goods.GoodsStore.service.IGoodsService;
import com.ruoyi.goods.GoodsStore.vo.GoodsStoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;

/**
 * 物品库存Controller
 *
 * @author ruoyi
 * @date 2022-11-27
 */
@RestController
@RequestMapping("/Goods/Goods")
public class GoodsController extends BaseController
{
    @Autowired
    private IGoodsService goodsService;

    /**
     * 查询物品库存列表
     */
    @PreAuthorize("@ss.hasPermi('Goods:Goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsStoreVo goodsStoreVo)
    {
        startPage();
        List<GoodsStoreVo> goodsList = goodsService.selectGoodsList(goodsStoreVo);
        return getDataTable(goodsList);
    }

    /**
     * 查询出入库明细库列表
     */
    @PreAuthorize("@ss.hasPermi('Goods:Goods:list')")
    @GetMapping("/detailed")
    public TableDataInfo detailedList(Long goodsId)
    {
        startPage();
        List<GoodsStoreVo> goodsList = goodsService.selectDetailedList(goodsId);
        return getDataTable(goodsList);
    }


    /**
     * 获取物品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('Goods:Goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(goodsService.getById(id));
    }

    /**
     * 新增物品库存
     */
    @PreAuthorize("@ss.hasPermi('Goods:Goods:add')")
    @Log(title = "物品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Goods goods)
    {
        return toAjax(goodsService.save(goods));
    }

    /**
     * 修改物品库存
     */
    @PreAuthorize("@ss.hasPermi('Goods:Goods:edit')")
    @Log(title = "物品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Goods goods)
    {
        return toAjax(goodsService.updateById(goods));
    }

    /**
     * 删除物品库存
     */
    @PreAuthorize("@ss.hasPermi('Goods:Goods:remove')")
    @Log(title = "物品库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(goodsService.deleteByIds(id));
    }
}
